/**
 * Created by wenyan on 2016/1/21.
 */
var timer;
var t;
var index=4;
var md_index=index;
var YaoJiangZhong = false ;
var title_all_show = true ;
var SYmingEr = 0;
var CanjiaRS=0;
var isMain=1;

$(document).ready(function(){
    toMain ();
});
function change () {
    action_url="cj.php";
    $.post(action_url,
        {
            geShu:J[index].MeiCiChou,
            pkls:"pkls"
        },
        function(data,status){

            document.getElementById('haoma').innerHTML = data;
            //document.getElementById('status').innerHTML = status;
            //document.getElementById('filterBtn').style.display= "block";
        }
    );
}

function cjrs () {
    action_url="cjrs.php";
    $.get(action_url,
        {
            pkls:"pkls"
        },
        function(data,status){
            CanjiaRS = data;
            document.getElementById('cjrs').innerHTML = data;
            //document.getElementById('status').innerHTML = status;
            //document.getElementById('filterBtn').style.display= "block";
        }
    );

    action_url="yi.php";
    $.get(action_url,
        {
            index:index
        },
        function(data,status){
            //alert('已抽：'+data);
            SYmingEr = parseFloat(data);
            document.getElementById('yichou').innerHTML=SYmingEr ;
            document.getElementById('mingEr').innerHTML=J[index].mingEr - SYmingEr ;
        }
    );
}



function write_result () {
    action_url="write_result.php";
    var zhongJiangHao = document.getElementById('haoma').innerHTML;
    //alert("zhongJiangHao : "+zhongJiangHao);
    $.post(action_url,
        {
            index:index,
            MeiCiChou:J[index].MeiCiChou,
            k:zhongJiangHao,
            v:J[index].name
        },
        function(data,status){
            cjrs ();
            //document.getElementById('status').innerHTML = status;
            //document.getElementById('filterBtn').style.display= "block";
        }
    );
}
function start () {
    if (YaoJiangZhong) {
        alert("请先停止正在进行的抽奖！");
        return false;
    };

    var tmp=parseFloat(document.getElementById('mingEr').innerHTML);
    if (tmp<=0) {
        alert(J[index].name+"抽奖名额已用完!");
        return false;
    };
    toMain ();
    $("#haoma").show(1000);
    isMain=0;
    clearInterval(timer);
    //setTimeout("change()",50);
    $('#haoma').css('font-size',J[index].fs);

    setTimeout("timer = setInterval('change()',45);",1);//timer = setInterval('change()',45); //随机数据变换速度，越小变换的越快
    YaoJiangZhong = true ;
}

function ok(){
    if (!YaoJiangZhong) {
        alert("请先按开始！"+J[index].name);
        return false;
    };
    YaoJiangZhong=0;
    clearInterval(timer);
    setTimeout("write_result()",50);
    cjrs ();
}


function  select_JiangXiang(argument) {
    if (YaoJiangZhong) {
        alert("请先停止正在进行的抽奖！");
        return false;
    };

    //onclick="select_JiangXiang()"
    if (argument=='p') {
        index=index-1;
    }
    if(argument=='n'){
        index=index+1;
    };
    if (index<0) {
        index=4;
    }
    if (index>4) {
        index=0;
    };
    if (argument=='b') {
        index=5;
        toMain();
    };
    reflash();
}

function reflash () {
    cjrs ();
    document.getElementById('J_name').innerHTML=J[index].name;
    document.getElementById('haoma').innerHTML='';
    document.getElementById('jp').innerHTML=J[index].JiangPin;
    document.getElementById('jp_img').src=J[index].JP_img;
    document.getElementById('mingEr').innerHTML=J[index].mingEr - SYmingEr ;

}

function showMD (argument) {
    action_url="yi.php";
    $.get(action_url,
        {
            index:index,
            ls:1
        },
        function(data,status){
            toMain ();
            $("#hjmd").show(1000);
            isMain = 0;
            document.getElementById('hjmd').innerHTML=J[index].name+':'+data ;
            md_index=index;
        }
    );
}
function md (argument) {
    action_url="yi.php";
    if (argument=='p') {
        md_index=md_index-1;
    }
    if(argument=='n'){
        md_index=md_index+1;
    };
    if (md_index<0) {
        md_index=4;
    }
    if (md_index>4) {
        md_index=0;
    };
    $.get(action_url,
        {
            index:md_index,
            ls:1
        },
        function(data,status){
            document.getElementById('hjmd').innerHTML=J[md_index].name+':'+data ;
        }
    );
}

function toMain () {
    $(".zheZhao,.zheZhao-black").hide(1000);
    isMain=1;
    reflash();
}

function showMenu(){
    toMain();
    $("#menu").show(1000);
    isMain=0;

}
function showHelp(){
    toMain();
    $("#help").show(1000);
    isMain=0;
}

